New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

wait-for-async

Package Overview
Dependencies
Maintainers
0
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wait-for-async

Async wait for

  • 0.7.13
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
775
decreased by-32.2%
Maintainers
0
Weekly downloads
 
Created
Source

wait-for-async

import waitFor from `wait-for-async`;

await waitFor({ interval, condition, times });

Wait for condition() to be true. Its value is checked every interval milliseconds, check no more than times intervals in total.

Whenever condition() becomes true, return true. If condition() never becomes true until times intervals passed, return false.

Parameters explained

interval

The intervals (in milliseconds) on how often to check condition()'s value. The default value is 100.

At least 1 interval will be waited before condition() is checked, even if condition() is true at the very beginning.

condition

condition() is a method that returns true or false. The default value is () => true.

times

How many times in total to check condition()'s value before giving up. The default value is Infinity.

These are the maximum times to check. Fewer times to check if condition()'s value becomes true sooner.

return value

true if condition() becomes true before giving up, otherwise return false.

Or simply put, condition()'s value will be returned.

Interesting use cases

Wait for file downloading

Wait for the download to become true (this variable should be updated by the file downloading code). Check the download value every second (the interval's default value is 100ms), and give up after 60 seconds(60 checks).

"Delay" the app for 3 seconds

await waitFor({ interval: 3000 });

FAQs

Package last updated on 04 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc